Repository navigation
fix(plugin-approvals): refuse an inverted delegation window and a self-delegation at the write - #33284
Conversation
…f-delegation at the write sys_approval_delegation declares two validation rules: validity_window_order (valid_until must be later than valid_from when both are set) and delegate_not_delegator (the delegate must differ from the delegator). Each is judged on insert and on an update that moves one of its columns, so a row stored before the rules existed stays inert and keeps taking unrelated edits. Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi Co-authored-by: Claude <noreply@anthropic.com>
…alidation messages (zh-CN translated) Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 7 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 5 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 6 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a71698527b303c8c2f5b00b92134ebb43157bbd9 && git checkout a71698527b303c8c2f5b00b92134ebb43157bbd9
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 7b27d05a6c7380c5508756ba2d67c8fca099636a && git checkout -B drift-repro 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 && git merge --no-ff 7b27d05a6c7380c5508756ba2d67c8fca099636a
node scripts/docs-audit/affected-docs.mjs --json 47a3b95ecc3960b3d57d2dfe9f082293096df9a3
|
The read-back helper erased its engine query options to `any`, which grew the test surface the query-options erasure ratchet holds at its ceiling. The options now `satisfies EngineQueryOptions`, matching the sibling integration tests; only the context stays loosely typed. Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi Co-authored-by: Claude <noreply@anthropic.com>
|
domain:server#5 · os-elon-musk · session_016WV4d1D3AzXvEhBbz79Pmi Request: review · area A3 · head |
|
Contract-review-claim: session_016WV4czuuneAppDnJbrNejw · head 7b27d05 · 2026-11-14T16:16Z review#2 (server area pilot, A3). |
Contract reviewServed-tier: Face: narrowing ( ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentAgainst Implemented-by: VERDICT: PASS |
|
domain:server#5 · os-elon-musk · session_016WV4d1D3AzXvEhBbz79Pmi ACCEPT · area A3
|
Requested by Elon · project thread
Fixes #33062
Area-lease pilot #33059, area A3.
What changes
sys_approval_delegationdeclares twovalidations(same shape assys_user_permission_set.validity_window_order):validity_window_order(cross_field, attaches tovalid_until): refused when both bounds are set andvalid_until <= valid_from(compared as instants withdatetime()).delegate_not_delegator(cross_field, attaches todelegate_id): refused whendelegate_id == delegator_id.Each rule is judged on insert (
previous == null) and on an update that moves one of its two columns, against the stored row overlaid with the patch. Validation runs afterbeforeInsert, so a delegator stamped bybindDelegationWriteGuardis judged too. Also: i18n bundles regenerated (zh-CN translated), one paragraph incontent/docs/automation/approvals.mdx, a patch changeset.approval-service.tsandsys-approval-action.object.tsare untouched.Why
Both shapes used to be stored with
201and then never rerouted an approval (isGrantActivedrops an inverted window; a self-delegate moves nothing), so the delegator believed their approvals were covered. Contract-first: refuse at the write instead of tolerating at resolution.Stored rows with either shape (from before this change) stay inert as before and keep taking unrelated edits; the remedy is to correct the dates or the delegate, or delete the row.
Verification
New
sys-approval-delegation-inert-shapes.integration.test.ts(realObjectQL+SqlDriver, write guard bound), 12 cases: inverted window and self-delegation refused for the delegator and a system writer (400 VALIDATION_FAILED, field +rule_violation, the rule's own message, no row stored); equal bounds refused; self-delegation via the guard's stamp refused; updates that invert the window or set the delegate to the delegator refused with the row unchanged; CONTROLs: valid window + different delegate lands, open-ended windows (either bound, or none) land, moving a bound within a valid window lands, a legacy inert row takes an unrelated edit and can be repaired.Ablation (also the premise check): object file reverted to origin/main at 4e6f7a5
Every red case failed with "expected the write to be refused, but it succeeded": on origin/main all eight writes land.
Local runs at b71b1de
pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2: Test Files 120 passed (120), Tests 1644 passed (1644)pnpm --filter @objectstack/plugin-approvals typecheck: exit 0 (check:test-typecheck: OK)node scripts/check-i18n-bundles.mjs --filter=approvals: in sync (21 bundles);pnpm check:i18n-stale-fill: OKnode scripts/check-adr-0087-registration.mjs --base origin/main: 1 declared-breaking changeset with a dispositioncheck:nul-bytes,check:doc-authoring,check:test-source-alias,check:cross-package-test-inputs,check:issue-citations,check-changeset-no-major,check-empty-changeset,check:registry-log-declared,check:role-word,check-affected-docs: exit 0The rest of the derived gate list is left to CI.
Clause-②: yes (narrowing)
Metadata-protocol: none
Human Minimum
packages/specholds no runtime logic.pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi